<?php

// $Id$


require_once(TANGRA_MAIN_DIR.'db/paginate_db_data.class.php');
require_once(TANGRA_MAIN_DIR.'grids/grid_ctrl.class.php');

require_once($WSC->get_site_inc_dir().'modules/tangra_cms/grids/images/images_grid.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/image/tcms_image_dbc.class.php');


class Images_Grid_Ctrl extends Grid_Ctrl {
	protected function create_grid() {
		$ret = new Images_Grid();

		return $ret;
	}


	protected function create_paginate_db_data() {
		$sqls = '';
		$sqlc = '';

		$pdbd = new Paginate_DB_Data($this->grid->get_page_size(), $sqls, $sqlc);

		return $pdbd;
	}


	public function process(DB_Connection $dbc, $page = NULL) {
		$vm = $this->get_vm();

		$sql = $this->get_sqls($vm);

		$this->paginate_db_data->set_sql_select($sql['sqls']);
		$this->paginate_db_data->set_sql_count($sql['sqlc']);

		parent::process($dbc, $page);
	}


	private function get_sqls($vm) {
		$filename = $vm->get_page_var('ci_image', 'filename');
		$notealt = $vm->get_page_var('ci_image', 'notealt');

		$sqls = TCMS_Image_DBC::get_sql_for_grid($filename, $notealt);
		$sqlc = TCMS_Image_DBC::get_sql_count_for_grid($filename, $notealt);

		$sql['sqls'] = $sqls;
		$sql['sqlc'] = $sqlc;

		return $sql;
	}
}